﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Web.Script.Serialization;

namespace ToolExcel
{
    public class CToolConfig
    {
        //当前语言
        public string LangCur = "LangChs";
        //导出文件
        public Dictionary<string, string> DictFile = new Dictionary<string, string>();
    }
    public static partial class XTool
    {
        public static CToolConfig ToolConfig = new CToolConfig();
        public static string ToolConfigFileName = @"\ToolConfig.json";

        public static void ToolConfigRead()
        {
            try
            {
                var path = Directory.GetCurrentDirectory() + ToolConfigFileName;
                if (File.Exists(path))
                {
                    FileStream fs = new FileStream(path, FileMode.Open);
                    StreamReader sr = new StreamReader(fs, Encoding.Default);

                    var jsonString = sr.ReadToEnd();
                    JavaScriptSerializer jss = new JavaScriptSerializer();
                    ToolConfig = jss.Deserialize<CToolConfig>(jsonString);

                    sr.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBoxShow($"ToolConfigRead 错误 {ex.Message}", "提示");
            }
        }
        public static void ToolConfigWrite()
        {
            try
            {
                var path = Directory.GetCurrentDirectory() + ToolConfigFileName;

                FileStream fs = new FileStream(path, FileMode.Create);
                StreamWriter sw = new StreamWriter(fs, Encoding.Default);

                JavaScriptSerializer jss = new JavaScriptSerializer();
                var jsonString = jss.Serialize(ToolConfig);

                sw.Write(jsonString);
                sw.Close();
            }
            catch (Exception ex)
            {
                MessageBoxShow($"ToolConfigWrite 错误 {ex.Message}", "提示");
            }
        }

    }
}
